home *** CD-ROM | disk | FTP | other *** search
Wrap
RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) NNNNaaaammmmeeee RWTPtrMap<K,T,C> - Rogue Wave library class SSSSyyyynnnnooooppppssssiiiissss #include <rw/tpmap.h> RWTPtrMap<K,T,C> m; SSSSttttaaaannnnddddaaaarrrrdddd CCCC++++++++ LLLLiiiibbbbrrrraaaarrrryyyy DDDDeeeeppppeeeennnnddddeeeennnntttt!!!! RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp requires the Standard C++ Library. DDDDeeeessssccccrrrriiiippppttttiiiioooonnnn This class maintains a pointer-based collection of associations of type ppppaaaaiiiirrrr<<<<KKKK**** ccccoooonnnnsssstttt,,,, TTTT****>>>>. The first part of the association is a key of type KKKK****, the second is its associated item of type TTTT****. Order is determined by the key according to a comparison object of type CCCC. CCCC must induce a total ordering on elements of type KKKK via a public member bool operator()(const K& x, const K& y) which returns ttttrrrruuuueeee if xxxx and its partner should precede yyyy and its partner within the collection. The structure lllleeeessssssss<<<<TTTT>>>> from the C++-standard header file <<<<ffffuuuunnnnccccttttiiiioooonnnnaaaallll>>>> is an example. Note that keys will be dereferenced before being compared. RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> will not accept a key that compares equal to any key already in the collection. (RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> may contain multiple keys that compare equal to each other.) Equality is based on the comparison object and not on the ======== operator. Given a comparison object ccccoooommmmpppp, keys aaaa and bbbb are equal if !comp(a,b) && !comp(b,a). PPPPeeeerrrrssssiiiisssstttteeeennnncccceeee Isomorphic. EEEExxxxaaaammmmpppplllleeeessss In this example, a map of RRRRWWWWCCCCSSSSttttrrrriiiinnnnggggs and RRRRWWWWDDDDaaaatttteeees is exercised. // // tpmap.cpp // #include <rw/tpmap.h> PPPPaaaaggggeeee 1111 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) #include <rw/cstring.h> #include <rw/rwdate.h> #include <iostream.h> #include <function.h> main(){ RWTPtrMap<RWCString, RWDate, less<RWCString> > birthdays; birthdays.insert ( new RWCString("John"), new RWDate(12, "April", 1975) ); birthdays.insert ( new RWCString("Ivan"), new RWDate(2, "Nov", 1980) ); // Alternative syntax: birthdays[new RWCString("Susan")] = new RWDate(30, "June", 1955); birthdays[new RWCString("Gene")] = new RWDate(5, "Jan", 1981); // Print a birthday: RWCString key("John"); cout << *birthdays[&key] << endl; return 0; } Program Output: 04/12/75 RRRReeeellllaaaatttteeeedddd CCCCllllaaaasssssssseeeessss Class RRRRWWWWTTTTPPPPttttrrrrMMMMuuuullllttttiiiiMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> offers the same interface to a pointer-based collection that accepts multiple keys that compare equal to each other. RRRRWWWWTTTTPPPPttttrrrrSSSSeeeetttt<<<<TTTT,,,,CCCC>>>> maintains a pointer-based collection of keys without the associated items. Class mmmmaaaapppp<<<<KKKK****,,,,TTTT****,,,,ddddeeeerrrreeeeffff____ccccoooommmmppppaaaarrrreeee<<<<CCCC,,,,KKKK,,,, aaaallllllllooooccccaaaattttoooorrrr>>>> >>>> is the C++-standard collection that serves as the underlying implementation for this collection. PPPPuuuubbbblllliiiicccc TTTTyyyyppppeeeeddddeeeeffffssss typedef rw_deref_compare<C,K> container_comp; typedef map<K*,T*,container_comp, allocator> container_type; typedef container_type::size_type size_type; typedef container_type::difference_type difference_type; typedef container_type::iterator iterator; typedef container_type::const_iterator const_iterator; typedef pair <K* const, T*> value_type; typedef pair <K* const, T*>& reference; typedef const pair <K* const, T*>& const_reference; typedef K* value_type_key; typedef T* value_type_data; typedef K*& reference_key; typedef T*& reference_data; typedef const K*const& const_reference_key; PPPPaaaaggggeeee 2222 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) typedef const T*const& const_reference_data; PPPPuuuubbbblllliiiicccc CCCCoooonnnnssssttttrrrruuuuccccttttoooorrrrssss RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> (const container_comp& comp = container_comp()); Constructs an empty map with comparator ccccoooommmmpppp. RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const RWTPtrMap<K,T,C>& rwm); Copy constructor. RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>>(const container_type& m); Constructs a map by copying all elements from mmmm. RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp<<<<KKKK,,,,TTTT,,,,CCCC>>>> (value_type* first,value_type* last, const container_comp& comp = container_comp()); Constructs a map by copying elements from the array of ppppaaaaiiiirrrrs pointed to by ffffiiiirrrrsssstttt, up to, but not including, the pair pointed to by llllaaaasssstttt. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr OOOOppppeeeerrrraaaattttoooorrrrssss RWTPtrMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const RWTPtrMap<K,T,C>& m); RWTPtrMap<K,T,C>& ooooppppeeeerrrraaaattttoooorrrr====(const container_type& m); Destroys all associations in self and replaces them by copying all associations from mmmm. bool ooooppppeeeerrrraaaattttoooorrrr<<<<(const RWTPtrMap<K,T,C>& m) const; Returns ttttrrrruuuueeee if self compares lexicographically less than mmmm, otherwise returns ffffaaaallllsssseeee. Keys in each collection are dereferenced before being compared. Assumes that type KKKK has well-defined less-than semantics. bool ooooppppeeeerrrraaaattttoooorrrr========(const RWTPtrMap<K,T,C>& m) const; Returns ttttrrrruuuueeee if self compares equal to mmmm, otherwise returns ffffaaaallllsssseeee. Two PPPPaaaaggggeeee 3333 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) collections are equal if both have the same number of entries, and iterating through both collections produces, in turn, individual keys that compare equal to each other. Keys are dereferenced before being compared. T*& ooooppppeeeerrrraaaattttoooorrrr[[[[]]]](const K* key); Looks up kkkkeeeeyyyy and returns a reference to its associated item. If the key is not in the dictionary, then it will be added with an associated uninitialized pointer of type TTTT****. Because of this, if there is a possibility that a key will not be in the dictionary, then this operator should only be used as an lvalue. PPPPuuuubbbblllliiiicccc MMMMeeeemmmmbbbbeeeerrrr FFFFuuuunnnnccccttttiiiioooonnnnssss void aaaappppppppllllyyyy(void (*fn)(const K*,T*&,void*),void* d); void aaaappppppppllllyyyy(void (*fn)(const K*,const T*,void*),void* d) const; Applies the user-defined function pointed to by ffffnnnn to every association in the collection. This function must have one of the prototypes: void yourfun(const K* key, T*& a, void* d); void yourfun(const K* key, const T* a, void* d); Client data may be passed through parameter dddd. void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(void (*fn)(const K*,T*&,void*),void* d); void aaaappppppppllllyyyyTTTTooooKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee (void (*fn)(const K*,const T*,void*),void* d) const; This is a deprecated version of the aaaappppppppllllyyyy member above. It behaves exactly the same as aaaappppppppllllyyyy. iterator bbbbeeeeggggiiiinnnn(); const_iterator bbbbeeeeggggiiiinnnn() const; PPPPaaaaggggeeee 4444 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) Returns an iterator positioned at the first pair in self. void cccclllleeeeaaaarrrr(); Clears the collection by removing all items from self. void cccclllleeeeaaaarrrrAAAAnnnnddddDDDDeeeessssttttrrrrooooyyyy(); Removes all associations from the collection and uses ooooppppeeeerrrraaaattttoooorrrr ddddeeeelllleeeetttteeee to destroy the objects pointed to by the keys and their associated items. Do not use this method if multiple pointers to the same object are stored. (This could happen even if keys all compare different, since items are not considered during comparison.) bool ccccoooonnnnttttaaaaiiiinnnnssss(const K* key) const; Returns ttttrrrruuuueeee if there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, otherwise returns ffffaaaallllsssseeee. bool ccccoooonnnnttttaaaaiiiinnnnssss(bool (*fn)(value_type,void*), void* d) const; Returns ttttrrrruuuueeee if there exists an association a in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, otherwise returns ffffaaaallllsssseeee. ffffnnnn points to a user-defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. iterator eeeennnndddd(); const_iterator eeeennnndddd() const; Returns an iterator positioned "just past" the last association in self. size_type eeeennnnttttrrrriiiieeeessss() const; PPPPaaaaggggeeee 5555 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) Returns the number of associations in self. const K* ffffiiiinnnndddd(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, then jjjj is returned. Otherwise, returns rrrrwwwwnnnniiiillll. value_type ffffiiiinnnndddd(bool (*fn)(value_type,void*), void* d) const; If there exists an association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee, then returns aaaa. Otherwise, returns ppppaaaaiiiirrrr<<<<rrrrwwwwnnnniiiillll,,,,rrrrwwwwnnnniiiillll>>>>. ffffnnnn points to a user-defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key); const T* ffffiiiinnnnddddVVVVaaaalllluuuueeee(const K* key) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, returns the item associated with jjjj. Otherwise, returns rrrrwwwwnnnniiiillll. const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, T*& tr); const K* ffffiiiinnnnddddKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(const K* key, const T*& tr) const; If there exists a key jjjj in self that compares equal to ****kkkkeeeeyyyy, assigns the item associated with jjjj to trrrr,,,, and returns jjjj. Otherwise, returns rrrrwwwwnnnniiiillll and leaves the value of ttttrrrr unchanged. bool iiiinnnnsssseeeerrrrtttt(K* key, T* a); PPPPaaaaggggeeee 6666 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) Adds kkkkeeeeyyyy with associated item aaaa to the collection. Returns ttttrrrruuuueeee if the insertion is successful, otherwise returns ffffaaaallllsssseeee. The function will return ttttrrrruuuueeee unless the collection already holds an association with the equivalent key. bool iiiinnnnsssseeeerrrrttttKKKKeeeeyyyyAAAAnnnnddddVVVVaaaalllluuuueeee(K* key, T* a); This is a deprecated version of the iiiinnnnsssseeeerrrrtttt member above. It behaves exactly the same as iiiinnnnsssseeeerrrrtttt. bool iiiissssEEEEmmmmppppttttyyyy() const; Returns ttttrrrruuuueeee if there are no items in the collection, ffffaaaallllsssseeee otherwise. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff(const K* key) const; Returns the number of keys jjjj in self that compare equal to ****kkkkeeeeyyyy. size_type ooooccccccccuuuurrrrrrrreeeennnncccceeeessssOOOOffff (bool (*fn)(value_type,void*), void* d) const; Returns the number of associations aaaa in self such that the expression((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee. ffffnnnn points to a user-defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. K* rrrreeeemmmmoooovvvveeee(const K* key); Removes the first association with key jjjj in self that compare euqal to ****kkkkeeeeyyyy and returns jjjj. Returns rrrrwwwwnnnniiiillll if there is no such association. K* rrrreeeemmmmoooovvvveeee(bool (*fn)(value_type,void*), void* d); Removes the first association aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd)))))))) is ttttrrrruuuueeee and returns its key. Returns rrrrwwwwnnnniiiillll if there is no such association. ffffnnnn points to a user-defined tester function which must PPPPaaaaggggeeee 7777 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(const K* key); Removes all associations with key jjjj in self that compare equal to ****kkkkeeeeyyyy. Returns the number of associations removed. size_type rrrreeeemmmmoooovvvveeeeAAAAllllllll(bool (*fn)(value_type,void*), void* d); Removes all associations aaaa in self such that the expression ((((((((****ffffnnnn))))((((aaaa,,,,dddd))))))))is ttttrrrruuuueeee. Returns the number removed. ffffnnnn points to a user- defined tester function which must have prototype: bbbboooooooollll yyyyoooouuuurrrrTTTTeeeesssstttteeeerrrr((((vvvvaaaalllluuuueeee____ttttyyyyppppeeee aaaa,,,, vvvvooooiiiidddd**** dddd))));;;; Client data may be passed through parameter dddd. container_type ssssttttdddd(); const container_type ssssttttdddd() const; Returns a reference to the underlying C++-standard collection that serves as the implementation for self. RRRReeeellllaaaatttteeeedddd GGGGlllloooobbbbaaaallll OOOOppppeeeerrrraaaattttiiiioooonnnnssss RWvostream& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWvostream& strm, const RWTPtrMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr<<<<<<<<(RWFile& strm, const RWTPtrMap<K,T,C>& coll); Saves the collection ccccoooollllllll onto the output stream ssssttttrrrrmmmm, or a reference to it if it has already been saved. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMap<K,T,C>& coll); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMap<K,T,C>& coll); PPPPaaaaggggeeee 8888 RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) RRRRWWWWTTTTPPPPttttrrrrMMMMaaaapppp((((3333CCCC++++++++)))) Restores the contents of the collection ccccoooollllllll from the input stream ssssttttrrrrmmmm. RWvistream& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWvistream& strm, RWTPtrMap<K,T,C>*& p); RWFile& ooooppppeeeerrrraaaattttoooorrrr>>>>>>>>(RWFile& strm, RWTPtrMap<K,T,C>*& p); Looks at the next object on the input stream ssssttttrrrrmmmm and either creates a new collection off the heap and sets pppp to point to it, or sets pppp to point to a previously read instance. If a collection is created off the heap, then you are responsible for deleting it. PPPPaaaaggggeeee 9999